package com.easytodo;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.ParsedRequestListener;
import com.androidnetworking.interfaces.StringRequestListener;
import com.easytodo.entity.Item;

import java.util.Collections;
import java.util.List;

public class ProjectItem extends AppCompatActivity {
    ListView itemList;

    public void getData(String path){
        AppCompatActivity that =this;

        Server.getProjectItem(path, new ParsedRequestListener<List<Item>>() {
            @Override
            public void onResponse(List<Item> response) {
                Collections.sort(response);

                itemList.setAdapter(new ItemAdapter(getBaseContext(), response, null, null, new StringRequestListener() {
                    @Override
                    public void onResponse(String response) {
                        getData(path);
                    }

                    @Override
                    public void onError(ANError anError) {

                    }
                },that));
            }

            @Override
            public void onError(ANError anError) {

            }
        });
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_todo);
        itemList=findViewById(R.id.todoList);
        ConstraintLayout layout=findViewById(R.id.me);
        layout.setPadding(0,0,0,0);
        String path=getIntent().getStringExtra("path");

        getData(path);
    }
}
